#!/usr/bin/perl -w
use strict;
use warnings;
use Math::Combinatorics;
use Math::NumberCruncher;
use Data::Dumper;
use Time::HiRes qw(gettimeofday tv_interval);
use Benchmark qw( cmpthese ) ;

#my $pept = 'O(177)S(23)OO(122)OOYOOT(21)OO';
#my $pept = 'A(737)TSSSSGS(21)LSATGR';
my @players = (1, 0, 0, 2, 0);

sub test_1{
    my $t1 = [gettimeofday];

    my %filtro;
    my $combinat = Math::Combinatorics->new(data => [@players]);

    my $t2 = [gettimeofday];

    while(my @perm = $combinat->next_permutation){
        $filtro{join ',', @perm} = \@perm;
    }
    my @combin = values %filtro;

    my $t3 = [gettimeofday];

    #print 't1 ', Dumper (tv_interval($t2, $t1)), "\n";
    #print 't2 ', Dumper (tv_interval($t3, $t2)), "\n";


    return @combin
}

sub test_2{
    my $t1 = [gettimeofday];

    my %filtro;
    my $combinat = Math::Combinatorics->new(data => [@players]);

    my $t2 = [gettimeofday];

    while(my @perm = $combinat->next_combination){
        $filtro{join ',', @perm} = \@perm;
    }
    my @combin = values %filtro;

    my $t3 = [gettimeofday];

    #print 't1 ', Dumper (tv_interval($t2, $t1)), "\n";
    #print 't2 ', Dumper (tv_interval($t3, $t2)), "\n";


    return @combin
}


sub test_3{
    my $t1 = [gettimeofday];

    my %filtro;
    my $combinat = Math::Combinatorics->new(data => [@players]);

    my $t2 = [gettimeofday];
    my @combin;
    my $string;

    while(my @perm = $combinat->next_permutation){
        $string = join ',', @perm;
        unless ($filtro{$string}){
            $filtro{$string} = 1;
            push @combin, \@perm;
        }
    }


    my $t3 = [gettimeofday];

    #print 't1 ', Dumper (tv_interval($t2, $t1)), "\n";
    #print 't2 ', Dumper (tv_interval($t3, $t2)), "\n";


    return @combin
}



#print "1\n", Dumper test_1;
#print "2\n", Dumper test_2;
#print "3\n", Dumper test_3;
#
#__END__

cmpthese(200, {
        a => \&test_1,
        #b => \&test_2,
        c => \&test_3,
        } );



1;
